﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace ECGServer
{
    class ThreadReceiveMessage
    {
        Thread thread;
       
        public ThreadReceiveMessage()
        {
        }

        public void run()
        {
            thread = new Thread(new ThreadStart(receiveMessage));
            thread.Start();
        }

        public void receiveMessage()
        {
            ECGServer.ServerTCPSocket.Start();
            while (true)
            {
                TcpClient client = ECGServer.ServerTCPSocket.AcceptTcpClient();
                
                //Handle connection request of client
                ThreadHandleTCPConnection thread = new ThreadHandleTCPConnection(client);
                ThreadPool.QueueUserWorkItem(thread.handleTCPConnection);
            }
        }

        public Thread Thread
        {
            get { return thread; }
        }
    }
}
